import { RouteRecordRaw } from "vue-router";
import HomeView from "@/views/HomeView.vue";
import UserLayout from "@/layouts/UserLayout.vue";
import UserLoginView from "@/views/user/UserLoginView.vue";
import UserRegisterView from "@/views/user/UserRegisterView.vue";
import AdminView from "@/views/AdminView.vue";
import NoAuthView from "@/views/NoAuthView.vue";
import ACCESS_ENUM from "@/access/accessEnum";
import AddQuestionView from "@/views/question/AddQuestionView.vue";
import ManageQuestionView from "@/views/question/ManageQuestionView.vue";
import QuestionsView from "@/views/question/QuestionsView.vue";
import QuestionSubmitView from "@/views/question/QuestionSubmitView.vue";
import ViewQuestionView from "@/views/question/ViewQuestionView.vue";
import AdminLayout from "@/layouts/AdminLayout/index.vue";
import AdminDashboard from "@/views/admin/dashboard/index.vue";
import AdminUserList from "@/views/admin/user/list.vue";
import AdminQuestionList from "@/views/admin/question/list.vue";
import ContestsView from "@/views/contest/ContestsView.vue";
import ContestDetailView from "@/views/contest/ContestDetailView.vue";
import AddContestView from "@/views/contest/AddContestView.vue";
import ContestProblemView from "@/views/contest/ContestProblemView.vue";

export const routes: Array<RouteRecordRaw> = [
  {
    path: "/user",
    name: "用户",
    component: UserLayout,
    children: [
      {
        path: "/user/login",
        name: "用户登录",
        component: UserLoginView,
      },
      {
        path: "/user/register",
        name: "用户注册",
        component: UserRegisterView,
      },
    ],
    meta: {
      hideInMenu: true,
    },
  },
  {
    path: "/",
    name: "主页",
    component: HomeView,
  },
  {
    path: "/questions",
    name: "浏览题目",
    component: QuestionsView,
  },
  {
    path: "/question_submit",
    name: "浏览题目提交",
    component: QuestionSubmitView,
  },
  {
    path: "/view/question/:id",
    name: "在线做题",
    component: ViewQuestionView,
    props: true,
    meta: {
      access: ACCESS_ENUM.USER,
      hideInMenu: true,
    },
  },
  {
    path: "/add/question",
    name: "创建题目",
    component: AddQuestionView,
    meta: {
      access: ACCESS_ENUM.USER,
    },
  },
  {
    path: "/update/question",
    name: "更新题目",
    component: AddQuestionView,
    meta: {
      access: ACCESS_ENUM.USER,
      hideInMenu: true,
    },
  },
  {
    path: "/manage/question/",
    name: "管理题目",
    component: ManageQuestionView,
    meta: {
      access: ACCESS_ENUM.ADMIN,
    },
  },
  // 竞赛相关路由
  {
    path: "/contests",
    name: "竞赛列表",
    component: ContestsView,
  },
  {
    path: "/contest/add",
    name: "创建竞赛",
    component: AddContestView,
    meta: {
      access: ACCESS_ENUM.ADMIN,
      hideInMenu: true,
    },
  },
  {
    path: "/contest/edit/:id",
    name: "编辑竞赛",
    component: AddContestView,
    props: true,
    meta: {
      access: ACCESS_ENUM.ADMIN,
      hideInMenu: true,
    },
  },
  {
    path: "/contest/:id",
    name: "竞赛详情",
    component: ContestDetailView,
    props: true,
    meta: {
      hideInMenu: true,
    },
  },
  {
    path: "/contest/:contestId/problem/:problemId",
    name: "竞赛题目",
    component: ContestProblemView,
    props: true,
    meta: {
      access: ACCESS_ENUM.USER,
      hideInMenu: true,
    },
  },

  // {
  //   path: "/hide",
  //   name: "隐藏页面",
  //   component: HomeView,
  //   meta: {
  //     hideInMenu: true,
  //   },
  // },
  {
    path: "/noAuth",
    name: "无权限",
    component: NoAuthView,
    meta: {
      hideInMenu: true,
    },
  },
  // 管理后台路由
  {
    path: "/admin",
    name: "管理后台",
    component: AdminLayout,
    redirect: "/admin/dashboard",
    meta: {
      access: ACCESS_ENUM.ADMIN,
      hideInMenu: true,
    },
    children: [
      {
        path: "dashboard",
        name: "仪表盘",
        component: AdminDashboard,
        meta: {
          access: ACCESS_ENUM.ADMIN,
        },
      },
      // 用户管理路由
      {
        path: "user/list",
        name: "用户管理",
        component: AdminUserList,
        meta: {
          access: ACCESS_ENUM.ADMIN,
        },
      },
      // 题目管理路由
      {
        path: "question/list",
        name: "题目管理",
        component: AdminQuestionList,
        meta: {
          access: ACCESS_ENUM.ADMIN,
        },
      },
      // 竞赛管理路由
      {
        path: "contest/list",
        name: "竞赛管理",
        component: ContestsView,
        meta: {
          access: ACCESS_ENUM.ADMIN,
        },
      },
      // 提交管理路由
      {
        path: "submit/list",
        name: "提交管理",
        component: QuestionSubmitView, // 复用现有组件
        meta: {
          access: ACCESS_ENUM.ADMIN,
        },
      },
      // 系统管理路由
      {
        path: "system/config",
        name: "系统设置",
        component: () => import("@/views/admin/system/ConfigView.vue"),
        meta: {
          access: ACCESS_ENUM.ADMIN,
        },
      },
      {
        path: "system/log",
        name: "系统日志",
        component: () => import("@/views/admin/system/LogView.vue"),
        meta: {
          access: ACCESS_ENUM.ADMIN,
        },
      },
    ],
  },
  // {
  //   path: "/about",
  //   name: "关于我的",
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () =>
  //     import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
  // },
];
